<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="售后标题" prop="aftersalestitle">
      <el-input v-model="dataForm.aftersalestitle" placeholder="售后标题"></el-input>
    </el-form-item>
    <el-form-item label="机构名称" prop="institutionname">
      <el-input v-model="dataForm.institutionname" placeholder="机构名称"></el-input>
    </el-form-item>
    <el-form-item label="售后类型" prop="aftersalestype">
      <el-input v-model="dataForm.aftersalestype" placeholder="售后类型"></el-input>
    </el-form-item>
    <el-form-item label="联系人" prop="contacts">
      <el-input v-model="dataForm.contacts" placeholder="联系人"></el-input>
    </el-form-item>
    <el-form-item label="重要级别" prop="importancelevel">
      <el-input v-model="dataForm.importancelevel" placeholder="重要级别"></el-input>
    </el-form-item>
    <el-form-item label="发布人" prop="publisher">
      <el-input v-model="dataForm.publisher" placeholder="发布人"></el-input>
    </el-form-item>
    <el-form-item label="发布日期" prop="dateofissue">
      <el-input v-model="dataForm.dateofissue" placeholder="发布日期"></el-input>
    </el-form-item>
    <el-form-item label="处理状态" prop="processingstatus">
      <el-input v-model="dataForm.processingstatus" placeholder="处理状态"></el-input>
    </el-form-item>
    <el-form-item label="操作" prop="operation">
      <el-input v-model="dataForm.operation" placeholder="操作"></el-input>
    </el-form-item>
    <el-form-item label="机构编号" prop="institutionid">
      <el-input v-model="dataForm.institutionid" placeholder="机构编号"></el-input>
    </el-form-item>
    <el-form-item label="省" prop="province">
      <el-input v-model="dataForm.province" placeholder="省"></el-input>
    </el-form-item>
    <el-form-item label="市" prop="city">
      <el-input v-model="dataForm.city" placeholder="市"></el-input>
    </el-form-item>
    <el-form-item label="售后内容" prop="salescontent">
      <el-input v-model="dataForm.salescontent" placeholder="售后内容"></el-input>
    </el-form-item>
    <el-form-item label="产品类别" prop="producttype">
      <el-input v-model="dataForm.producttype" placeholder="产品类别"></el-input>
    </el-form-item>
    <el-form-item label="产品状态" prop="productstatus">
      <el-input v-model="dataForm.productstatus" placeholder="产品状态"></el-input>
    </el-form-item>
    <el-form-item label="发布部门" prop="publishdept">
      <el-input v-model="dataForm.publishdept" placeholder="发布部门"></el-input>
    </el-form-item>
    <el-form-item label="关注者" prop="followman">
      <el-input v-model="dataForm.followman" placeholder="关注者"></el-input>
    </el-form-item>
    <el-form-item label="处理部门" prop="dealdept">
      <el-input v-model="dataForm.dealdept" placeholder="处理部门"></el-input>
    </el-form-item>
    <el-form-item label="处理者" prop="dealman">
      <el-input v-model="dataForm.dealman" placeholder="处理者"></el-input>
    </el-form-item>
    <el-form-item label="结束日期" prop="finishdate">
      <el-input v-model="dataForm.finishdate" placeholder="结束日期"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          aftersalestitle: '',
          institutionname: '',
          aftersalestype: '',
          contacts: '',
          importancelevel: '',
          publisher: '',
          dateofissue: '',
          processingstatus: '',
          operation: '',
          institutionid: '',
          province: '',
          city: '',
          salescontent: '',
          producttype: '',
          productstatus: '',
          publishdept: '',
          followman: '',
          dealdept: '',
          dealman: '',
          finishdate: ''
        },
        dataRule: {
          aftersalestitle: [
            { required: true, message: '售后标题不能为空', trigger: 'blur' }
          ],
          institutionname: [
            { required: true, message: '机构名称不能为空', trigger: 'blur' }
          ],
          aftersalestype: [
            { required: true, message: '售后类型不能为空', trigger: 'blur' }
          ],
          contacts: [
            { required: true, message: '联系人不能为空', trigger: 'blur' }
          ],
          importancelevel: [
            { required: true, message: '重要级别不能为空', trigger: 'blur' }
          ],
          publisher: [
            { required: true, message: '发布人不能为空', trigger: 'blur' }
          ],
          dateofissue: [
            { required: true, message: '发布日期不能为空', trigger: 'blur' }
          ],
          processingstatus: [
            { required: true, message: '处理状态不能为空', trigger: 'blur' }
          ],
          operation: [
            { required: true, message: '操作不能为空', trigger: 'blur' }
          ],
          institutionid: [
            { required: true, message: '机构编号不能为空', trigger: 'blur' }
          ],
          province: [
            { required: true, message: '省不能为空', trigger: 'blur' }
          ],
          city: [
            { required: true, message: '市不能为空', trigger: 'blur' }
          ],
          salescontent: [
            { required: true, message: '售后内容不能为空', trigger: 'blur' }
          ],
          producttype: [
            { required: true, message: '产品类别不能为空', trigger: 'blur' }
          ],
          productstatus: [
            { required: true, message: '产品状态不能为空', trigger: 'blur' }
          ],
          publishdept: [
            { required: true, message: '发布部门不能为空', trigger: 'blur' }
          ],
          followman: [
            { required: true, message: '关注者不能为空', trigger: 'blur' }
          ],
          dealdept: [
            { required: true, message: '处理部门不能为空', trigger: 'blur' }
          ],
          dealman: [
            { required: true, message: '处理者不能为空', trigger: 'blur' }
          ],
          finishdate: [
            { required: true, message: '结束日期不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/com/aftersaleslog/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.aftersalestitle = data.aftersaleslog.aftersalestitle
                this.dataForm.institutionname = data.aftersaleslog.institutionname
                this.dataForm.aftersalestype = data.aftersaleslog.aftersalestype
                this.dataForm.contacts = data.aftersaleslog.contacts
                this.dataForm.importancelevel = data.aftersaleslog.importancelevel
                this.dataForm.publisher = data.aftersaleslog.publisher
                this.dataForm.dateofissue = data.aftersaleslog.dateofissue
                this.dataForm.processingstatus = data.aftersaleslog.processingstatus
                this.dataForm.operation = data.aftersaleslog.operation
                this.dataForm.institutionid = data.aftersaleslog.institutionid
                this.dataForm.province = data.aftersaleslog.province
                this.dataForm.city = data.aftersaleslog.city
                this.dataForm.salescontent = data.aftersaleslog.salescontent
                this.dataForm.producttype = data.aftersaleslog.producttype
                this.dataForm.productstatus = data.aftersaleslog.productstatus
                this.dataForm.publishdept = data.aftersaleslog.publishdept
                this.dataForm.followman = data.aftersaleslog.followman
                this.dataForm.dealdept = data.aftersaleslog.dealdept
                this.dataForm.dealman = data.aftersaleslog.dealman
                this.dataForm.finishdate = data.aftersaleslog.finishdate
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/com/aftersaleslog/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'aftersalestitle': this.dataForm.aftersalestitle,
                'institutionname': this.dataForm.institutionname,
                'aftersalestype': this.dataForm.aftersalestype,
                'contacts': this.dataForm.contacts,
                'importancelevel': this.dataForm.importancelevel,
                'publisher': this.dataForm.publisher,
                'dateofissue': this.dataForm.dateofissue,
                'processingstatus': this.dataForm.processingstatus,
                'operation': this.dataForm.operation,
                'institutionid': this.dataForm.institutionid,
                'province': this.dataForm.province,
                'city': this.dataForm.city,
                'salescontent': this.dataForm.salescontent,
                'producttype': this.dataForm.producttype,
                'productstatus': this.dataForm.productstatus,
                'publishdept': this.dataForm.publishdept,
                'followman': this.dataForm.followman,
                'dealdept': this.dataForm.dealdept,
                'dealman': this.dataForm.dealman,
                'finishdate': this.dataForm.finishdate
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
